package com.study.行为型模式.命令模式;

public class LightOffCommand implements Command{

    //将接收者通过构造器聚合进来
    private LightReceiver receiver;
    public LightOffCommand(LightReceiver receiver){
        this.receiver = receiver;
    }

    //execute调用命令接收者的什么方法由  当前类的业务逻辑决定
    @Override
    public void execute() {
        //关闭电灯
        receiver.off();
    }

    @Override
    public void undo() {
        //撤销操作，即打开电灯
        System.out.println("撤销关闭电灯");
        receiver.on();

    }
}
